package com.ticket.sass.provider.business.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.ticket.sass.common.entity.tenant.CinemaEntity;
import com.ticket.sass.common.exception.enums.ErrorCode;
import com.ticket.sass.common.exception.exception.BadRequestException;
import com.ticket.sass.provider.business.CinemaBusiness;
import com.ticket.sass.provider.config.AppConfig;
import com.ticket.sass.provider.dto.cinema.CinemaListInput;
import com.ticket.sass.provider.dto.cinema.CinemaListOutput;
import com.ticket.sass.provider.service.PageModel;
import com.ticket.sass.provider.service.impl.CinemaServiceImpl;
import com.ticket.sass.provider.service.impl.TenantCinemaMapServiceImpl;
import com.ticket.sass.provider.util.ModelUtil;
import lombok.AllArgsConstructor;
import org.modelmapper.TypeToken;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @author ywb
 * @date 2024-03-15 15:45
 */
@Service
@AllArgsConstructor
@Transactional(rollbackFor = Exception.class)
public class CinemaBusinessImpl implements CinemaBusiness {
    final AppConfig appConfig;
    final ModelUtil modelUtil;
    final CinemaServiceImpl service;
 
    final TenantCinemaMapServiceImpl tenantCinemaMapService;
  
    
    
    @Override
    public PageModel<CinemaListOutput> list(CinemaListInput input) {
        IPage<CinemaEntity> page = service.iPage(input);
        List<CinemaListOutput> outputs = modelUtil.listToList(page.getRecords(), new TypeToken<List<CinemaListOutput>>(){}.getType());
       
        
        return new PageModel<>(page.getTotal(), outputs);
    }
    
  
    
    private void validateId(Long id) {
        if (service.isEmpty(id)) {
            throw new BadRequestException(
                ErrorCode.RECORD_NOT_EXIST,
                ErrorCode.RECORD_NOT_EXIST.getReasonPhrase()
            );
        }
    }
}
